<#include "/tags/likeTag.ftl">
<#include "/tags/likeListTag.ftl">
<#include "/tags/commentTag.ftl">
<#include "/tags/commentBoxTag.ftl">
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />

<#macro commentsPkg componentId component comments commentCount=0 likeCount=0 youLikeThis=false
		showSettings="on" showDeleteComponent="off" showEditComponent="on" showCommentInput="on" showLikeButton="on" entryOwner="">
	<#if (showSettings=="on")>
		<#assign editType="entry"/>
		<div class="entrySetting">
	        <ul>
	            <li class="fl"><label class="commentCount">(${commentCount})</label></li>
	            <li class="fl sprLine"><a href="#" title="Viết ý kiến" rel="${component}${componentId}" class="entryComment commentCount componentCount <#if (commentCount>0)>entryCommentSelected</#if>"></a></li>
	            <#if (showEditComponent == "on")>
		            <@security.authorize ifAnyGranted="ROLE_USER">
			            <#if (entryOwner == data.userInSession)>
			            	<#if component == "GOAL_ENTRY">
			            		<li class="fl sprLine"><a href="${rc.contextPath}/entry/edit/${componentId}" title="Sửa bài viết" class="entryEdit"></a></li>
		            		</#if>
			            	<#if component == "DONE_ENTRY">
			            		<li class="fl sprLine"><a href="${rc.contextPath}/done/edit/${componentId}" title="Sửa bài viết" class="entryEdit"></a></li>
		            		</#if>
			            </#if>
		            </@security.authorize>
	            </#if>
	            <#if (showDeleteComponent == "on")>
	            <@security.authorize ifAnyGranted="ROLE_USER">
	            <#if (entryOwner == data.userInSession)>
	            <li class="fl"><a rel="${component};${componentId}" href="#" title="Xóa bài viết" class="entryDelete"></a></li>
	            </#if>
	            </@security.authorize>
	            </#if>
	            <#if (showLikeButton == "on")>
	            <@security.authorize ifAnyGranted="ROLE_USER">
	            <li class="fr">
	            	${youLikeThis?string("<a href='javascript:unlike(\"${component}\", ${componentId});' title='Thích' class='entryLikeThis entryLikeThisSelected' rel='${component}_${componentId}_like_button'></a>",
	            	"<a href='javascript:like(\"${component}\", ${componentId});' title='Thích' class='entryLikeThis' rel='${component}_${componentId}_unlike_button'></a>")}	            	
	            </li>
	            </@security.authorize>
	            </#if>
	            <li class="fr listfriendLikeThis"><span><@likeList likeCount=likeCount entryId=componentId youLikeThis=youLikeThis component=component /></span></li>
	         </ul>   
	     </div>
     </#if>
     <div id="comment">
        <#if comments?exists>
        	<div class="comment_list ${component}${componentId}" rel="${component}${componentId}">
		    	<#if commentCount gt 2>
		     		<#assign lastComment = -1/>
		    		<#list comments as comment>
					   <#if lastComment lt 0 || lastComment gt comment.updateDate>
		    		   	   <#assign lastComment = comment.updateDate />
					   </#if>
		    		</#list>
		     		<div id="old_comment_${component}_${componentId}" class="viewMoreComment"> 
			     		<a href="javascript:loadOldComments('${component}', '${componentId}', '${entryOwner}', '${lastComment}')">Hiển thị tất cả các bình luận (${commentCount})</a>
					</div>
		     	</#if>
		    	<#list comments as comment>
		        	<@commentView avatarURL=comment.avatarURL ownerName=comment.ownerName commentId=comment.id commentType=comment.component body=comment.comment commentUpdatedSince=comment.updatedSince entryOwner=entryOwner/>
		        	<#if comment_has_next>		          
		   				
		          	</#if>
		        </#list>
	        </div>
        </#if>
        <#if (showCommentInput=="on")>
        <@security.authorize ifAnyGranted="ROLE_USER">
        	<@commentBox component=component componentId=componentId />
        </@security.authorize>
        </#if>
    </div> 
</#macro>